package com.swfgui.utils
{
	public class TimeUtil
	{
		public function TimeUtil()
		{
		}
		
		/**
		 * value -> xx天xx时xx分xx秒
		 * @param value 单位：秒
		 */
		public static function formatTime1(value:int):String
		{
			var day:int = value / 86400;
			var hour:int = value % 86400 / 3600;
			var minute:int = value % 3600 / 60;
			var second:int = value % 60;
			
			var rtv:String="";
			
			if(day > 0)
			{
				rtv += day.toString() + "天";
			}
			
			if(hour > 0)
			{
				rtv += timeIntToString(hour) + "时";
			}
			
			if(minute > 0)
			{
				rtv += timeIntToString(minute) + "分";
			}
			
			return rtv + timeIntToString(second) + "秒";
		}
		
		/**
		 * value -> xx天 xx:xx:xx
		 * @param value 单位：秒
		 * @return 
		 */
		public static function formatTime2(value:int):String
		{
			var day:int = value / 86400;
			var hour:int = value % 86400 / 3600;
			var minute:int = value % 3600 / 60;
			var second:int = value % 60;
			
			if(day > 0)
			{
				return day.toString() + "天" + timeIntToString(hour) + "小时";
			}
			else if(hour > 0)
			{
				return timeIntToString(hour) + ":" + timeIntToString(minute) + ":" + timeIntToString(second);
			}
			else
			{
				return timeIntToString(minute) + ":" + timeIntToString(second);
			}
		}

		public static var formatedDate:Date;
		
		/**
		 * 121334 -> 01-20 15:05
		 * @param value 1970.1.1到现在的秒数
		 * @return 
		 */
		public static function formatDate(value:int):String
		{
			var date:Date = new Date();
			date.setTime(value * 1000);
			
			return timeIntToString(date.month + 1) + "-" + 
				timeIntToString(date.date) + " " + 
				timeIntToString(date.hours) + ":" + 
				timeIntToString(date.minutes);
		}
		
		/**
		 * value -> xx天、xx小时、xx分钟、xx秒，没有零头则不返回零头
		 * @param value 单位：秒
		 * @return 
		 */
		public static function formatTime3(value:int, useXX:Boolean=true):String			
		{			
			var day:int = value / 86400;
			var hour:int = value % 86400 / 3600;
			var minute:int = value % 3600 / 60;
			var second:int = value % 60;
			
			if(day > 0)
			{
				return timeIntToString(day, useXX); + "天" + (hour > 0 ? timeIntToString(hour, useXX) + "小时" : "");
			}
			else if(hour > 0)
			{
				return timeIntToString(hour, useXX) + "小时" + (minute > 0 ? timeIntToString(minute, useXX) + "分钟" : "");
			}
			else if(minute > 0)
			{
				return timeIntToString(minute, useXX) + "分钟" + (second > 0 ? timeIntToString(second, useXX) + "秒" : "");
			}
			else
			{
				return timeIntToString(second, useXX) + "秒";
			}
		}
		
		private static function timeIntToString(value:int, useXX:Boolean=true):String
		{
			return (!useXX || value > 9) ? value.toString() : "0" + value.toString();
		}
	}
}